package responsitory;

import com.google.gson.reflect.TypeToken;

import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import bean.BankCodeBean;
import bean.HomeMallBean;
import bean.measge_bean.WeiXiuiJiLuBean;
import bean.personal_bean.MoneyShengyuBean;
import interfaces.IMessgeInterface;
import util.volley.BaseErrorListener;
import util.volley.BaseNetRepository;
import util.volley.BaseSuccessReqListener;
import util.volley.ByJsonRequest;
import util.volley.ICompleteListener;

/**
 * Created by itboye on 2016/12/5.
 */

public class SystemMessgePresponsitory extends BaseNetRepository implements IMessgeInterface<String> {
    public static final String APIKEY = "100";
    public static final String SystemMessge = "";//系统消息
    public static final String RepairMessg = "";//维修 消息

    public static final String Yuen = "By_Wallet_detail";//余额
    public static final String Tixian = "By_Wallet_apply";//提现

    public static final String Pwass = "By_Wallet_setSecret";//设置密码或者重置
    public static final String WeiXiuJiLu = "By_Repair_queryList";//维修记录
    public static final String BandingType = "By_Wallet_bindType";//支持账号类型

    public static final String PWD = "By_Wallet_checkSecret";//支持账号类型

    public SystemMessgePresponsitory(ICompleteListener iCompleteListener) {
        super(iCompleteListener);
    }

    /**
     * 系统消息
     *
     * @param uid
     * @param type
     */
    @Override
    public void onSystemMessge(String uid, String type) {
        Type Type = new TypeToken<HomeMallBean>() {
        }.getType();
//        String apiVer = api;
        Map<String, Object> map = new HashMap<>();
        map.put("uid", uid);
        map.put("id", type);

        (new ByJsonRequest.Builder<HomeMallBean>())
                .setTypeVerParamsAndReturnClass(APIKEY, SystemMessge, map, Type)
                .requestListener(
                        new BaseSuccessReqListener<HomeMallBean>(
                                getListener()))
                .errorListener(new BaseErrorListener(getListener()))
                .desEncodeThenBuildAndSend();
    }

    /**
     * 维修消息
     *
     * @param uid
     * @param id
     */
    @Override
    public void onRepairMessge(String uid, String id) {
        Type Type = new TypeToken<HomeMallBean>() {
        }.getType();
//        String apiVer = api;
        Map<String, Object> map = new HashMap<>();
        map.put("uid", uid);
        map.put("id", id);

        (new ByJsonRequest.Builder<HomeMallBean>())
                .setTypeVerParamsAndReturnClass(APIKEY, RepairMessg, map, Type)
                .requestListener(
                        new BaseSuccessReqListener<HomeMallBean>(
                                getListener()))
                .errorListener(new BaseErrorListener(getListener()))
                .desEncodeThenBuildAndSend();
    }

    @Override
    public void onMoneySys(String uid, String account_id, String money) {
        Type Type = new TypeToken<String>() {
        }.getType();
//        String apiVer = api;
        Map<String, Object> map = new HashMap<>();
        map.put("uid", uid);
        map.put("account_id", account_id);
        map.put("money", money);
        (new ByJsonRequest.Builder<String>())
                .setTypeVerParamsAndReturnClass(Tixian, APIKEY, map, Type)
                .requestListener(
                        new BaseSuccessReqListener<String>(
                                getListener()))
                .errorListener(new BaseErrorListener(getListener()))
                .desEncodeThenBuildAndSend();
    }

    @Override
    public void onWallet(String uid, String news) {
        Type Type = new TypeToken<String>() {
        }.getType();
//        String apiVer = api;
        Map<String, Object> map = new HashMap<>();
        map.put("uid", uid);
        map.put("new", news);
        (new ByJsonRequest.Builder<String>())
                .setTypeVerParamsAndReturnClass(Pwass, APIKEY, map, Type)
                .requestListener(
                        new BaseSuccessReqListener<String>(
                                getListener()))
                .errorListener(new BaseErrorListener(getListener()))
                .desEncodeThenBuildAndSend();
    }

    @Override
    public void onMoney(String uid) {
        Type Type = new TypeToken<MoneyShengyuBean>() {
        }.getType();
//        String apiVer = api;
        Map<String, Object> map = new HashMap<>();
        map.put("uid", uid);
        (new ByJsonRequest.Builder<MoneyShengyuBean>())
                .setTypeVerParamsAndReturnClass(Yuen, APIKEY, map, Type)
                .requestListener(
                        new BaseSuccessReqListener<MoneyShengyuBean>(
                                getListener()))
                .errorListener(new BaseErrorListener(getListener()))
                .desEncodeThenBuildAndSend();
    }

    @Override
    public void onRememberPay(String uid, String old, String news) {
        Type Type = new TypeToken<String>() {
        }.getType();
//        String apiVer = api;
        Map<String, Object> map = new HashMap<>();
        map.put("uid", uid);
        map.put("old", old);
        map.put("new", news);
        (new ByJsonRequest.Builder<String>())
                .setTypeVerParamsAndReturnClass(Pwass, APIKEY, map, Type)
                .requestListener(
                        new BaseSuccessReqListener<String>(
                                getListener()))
                .errorListener(new BaseErrorListener(getListener()))
                .desEncodeThenBuildAndSend();
    }

    @Override
    public void onWeiXiuJiLu(String uid, String id, String current_page, String per_page) {
        Type Type = new TypeToken<WeiXiuiJiLuBean>() {
        }.getType();
        String apiVer = "101";
        Map<String, Object> map = new HashMap<>();
        map.put("uid", uid);
        map.put("group_id", id);
        map.put("current_page", current_page);
        map.put("per_page", per_page);

        (new ByJsonRequest.Builder<WeiXiuiJiLuBean>())
                .setTypeVerParamsAndReturnClass(WeiXiuJiLu, apiVer, map, Type)
                .requestListener(
                        new BaseSuccessReqListener<WeiXiuiJiLuBean>(
                                getListener()))
                .errorListener(new BaseErrorListener(getListener()))
                .desEncodeThenBuildAndSend();
    }

    @Override
    public void onBangDinType() {
        Type Type = new TypeToken<List<BankCodeBean>>() {
        }.getType();
        Map<String, Object> map = new HashMap<>();


        (new ByJsonRequest.Builder<List<BankCodeBean>>())
                .setTypeVerParamsAndReturnClass(BandingType, "100", map, Type)
                .requestListener(
                        new BaseSuccessReqListener<List<BankCodeBean>>(
                                getListener()))
                .errorListener(new BaseErrorListener(getListener()))
                .desEncodeThenBuildAndSend();
    }

    @Override
    public void onByWalletCheckSecret(String uid, String secret) {
        Type Type = new TypeToken<List<BankCodeBean>>() {
        }.getType();
        Map<String, Object> map = new HashMap<>();
        map.put("uid", uid);
        map.put("secret", secret);

        (new ByJsonRequest.Builder<List<BankCodeBean>>())
                .setTypeVerParamsAndReturnClass(PWD, "100", map, Type)
                .requestListener(
                        new BaseSuccessReqListener<List<BankCodeBean>>(
                                getListener()))
                .errorListener(new BaseErrorListener(getListener()))
                .desEncodeThenBuildAndSend();
    }
}
